package zzc.imsystem.ims.Controller;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import zzc.imsystem.ims.Servlet.LoginService;


import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@RestController
public class IMloginControl {
    @Autowired
    private LoginService loginService;


    /**
     * 登录注册模块控制层
     * @param request
     * @param response
     * @param session
     * @return
     */
    @RequestMapping(value = "/imlogin",method ={RequestMethod.POST,RequestMethod.GET})

    public Object imLoginControl(HttpServletRequest request, HttpServletResponse response,HttpSession session){
        String id = request.getParameter("id");
        String password = request.getParameter("password");
        //System.out.println(id+"  "+password);

        Object flag = loginService.loginService(id,password);
        //登录业务判断
        if (flag!=null){
            //System.out.println("登录成功");
            try {
                response.sendRedirect("/home.html");
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("重定向网页出错");
            }
        }else{
            //System.out.println("失败");
            try {
                response.sendRedirect("/login.html");
            } catch (IOException e) {
                e.printStackTrace();
                System.out.println("重定向网页出错");
            }
        }

        return flag;

    }


}
